package com.boco.pciv.controller.project;

import com.boco.pciv.controller.PcivController;
import com.boco.pciv.controller.company.CompanyController;
import com.boco.pciv.core.entity.*;
import com.boco.pciv.core.security.LoginUser;
import com.boco.pciv.core.util.SearchUtil;
import com.boco.pciv.entity.page.*;
import com.boco.pciv.entity.project.CompanyProjectInfo;
import com.boco.pciv.service.project.IPageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value="/page/")
public class PageController extends PcivController {
    Logger logger = LoggerFactory.getLogger(CompanyController.class);

    @Resource
    private IPageService iPageService;


    @GetMapping("/prolist")
    public BizResponse getProList(String time) {
        SearchCriteria param = new SearchCriteria();
        LoginUser user=getCurUser();
        String companyid="";
        if(user.getUserType()!=0){
            companyid=user.getDeptId();
        }
        param.putCriteria("companyid", companyid);
        List<CompanyProjectInfo> result = iPageService.getProjectListInfo(param);
        addOperationLog("查询", "劳务公司首页项目块数据源查询");
        return  BizResponseUtil.list(result);
    }
    @PostMapping("/proLineInfo")
    public BizResponse getproLineInfo() {
        LoginUser user=getCurUser();
        String companyid="";
        if(user.getUserType()!=0){
            companyid=user.getDeptId();
        }
        resultLine result = iPageService.getproLineInfo(companyid);
        addOperationLog("查询", "劳务公司首页曲线数据源查询");
        return BizResponseUtil.single(result);
    }
    @PostMapping("/proPieInfo")
    public BizResponse getproPieInfo() {
        LoginUser user=getCurUser();
        String companyid="";
        if(user.getUserType()!=0){
            companyid=user.getDeptId();
        }
        resultPie result = iPageService.getproPieInfo(companyid);
        addOperationLog("查询", "劳务公司首页饼图数据源查询");
        return BizResponseUtil.single(result);
    }
    @PostMapping("/proinfo")
    public BizResponse getproinfo() {
        LoginUser user=getCurUser();
        String companyid="";
        if(user.getUserType()!=0){
            companyid=user.getDeptId();
        }
        CompanyProjectInfo result = iPageService.getproinfo(companyid);
        addOperationLog("查询", "首页项目块数据源查询");
        return BizResponseUtil.single(result);
    }
    @PostMapping("/getBarData")
    public BizResponse getBarData(String type) {
        LoginUser user=getCurUser();
        String companyid="";
        if(user.getUserType()!=0){
            companyid=user.getDeptId();
        }

        if("bar".equals(type.toLowerCase())) {
            resultBar result = iPageService.getBarData(companyid);
            addOperationLog("查询", "首页各月总工资源查询");
            return BizResponseUtil.single(result);
        }
        else{
            resultBar result = iPageService.getBarRData(companyid);
            addOperationLog("查询", "首页各项目总工资源查询");
            return BizResponseUtil.single(result);
        }
    }

}
